package com.arrogames.blondbattle.game
{
	import ash.core.Engine;
	import ash.core.Entity;
	import com.arrogames.blondbattle.game.graphics.ui.GameOverDisplay;
	import com.arrogames.blondbattle.game.movement.Motion;
	import com.arrogames.blondbattle.game.combat.Unit;
	import com.arrogames.blondbattle.game.purchases.Cooldown;
	import com.arrogames.blondbattle.game.rendering.Display;
	import com.arrogames.blondbattle.game.state.Money;
	import com.arrogames.blondbattle.game.movement.Position;
	import com.arrogames.blondbattle.game.purchases.Order;
	import com.arrogames.blondbattle.game.rendering.UIDisplay;
	import com.arrogames.blondbattle.game.graphics.ui.MoneyLabel;
	import com.arrogames.blondbattle.game.graphics.ui.PurchaseButton;
	import com.arrogames.blondbattle.model.UnitDefinition;
	import com.arrogames.blondbattle.ui.buttons.MusicButton;
	import org.as3commons.logging.api.getLogger;
	import org.as3commons.logging.api.ILogger;
	
	public class UIEntityCreator {
		private static const logger:ILogger = getLogger(EntityCreator);
		
		private var engine : Engine;
		
		public function UIEntityCreator( engine : Engine ) {
			this.engine = engine;
		}
		
		public function destroyEntity( entity : Entity ) : void {
			engine.removeEntity( entity );
		}
		
		public function createPurchaseButton(unit:UnitDefinition, x:Number, y:Number, buttonSize:Number):Entity {
			var entity : Entity = new Entity()
				.add( new UIDisplay( new PurchaseButton(unit, buttonSize) ) )
				.add( new Position( x, y, 0 ) )
				.add( new Unit(unit.name) );
			engine.addEntity( entity );
			return entity;
		}
		
		public function createMoneyLabel(x:Number, y:Number, money:Money):Entity {
			var entity : Entity = new Entity()
				.add( new UIDisplay( new MoneyLabel(money) ) )
				.add( new Position( x, y, 0 ) );
				
			engine.addEntity( entity );
			return entity;
		}
		
		public function createMuteButton(muted:Boolean) : Entity {
			var entity : Entity = new Entity()
				.add( new UIDisplay( new MusicButton(muted) ) )
				.add( new Position( 10, 10, 0 ) );
				
			engine.addEntity( entity );
			return entity;
		}
		
		public function createDrawGraphic():Entity {
			return createGameOverDisplay(GameOverDisplay.DRAW);
		}
		
		public function createLossGraphic():Entity {
			return createGameOverDisplay(GameOverDisplay.LOSS);
		}
		
		public function createWinGraphic():Entity {
			return createGameOverDisplay(GameOverDisplay.WIN);
		}
		
		private function createGameOverDisplay(type:int):Entity {
			var display:GameOverDisplay = new GameOverDisplay(type);
			var entity : Entity = new Entity()
				.add( new UIDisplay( display ) )
				.add( new Position( 400, 225, 0 ) );
				
			engine.addEntity( entity );
			return entity;
		}
	}
}
